package main

import (
	"errors"
	"fmt"
	"net/http"
	"net/rpc"
	"time"
)

//usage: go run rpc_http_server.go
//used with rpc_http_client.go

type Args struct {
	A,B int
}

type Quotient struct {
	Quo,Rem int
}

type Arith int

func (t *Arith)Multiply(args *Args,reply *int)error {
	*reply=args.A*args.B
	fmt.Println("call Arith.Multiply ... ",time.Now())
	return nil
}

func (t *Arith)Divide(args *Args,quo *Quotient)error {
	if args.B==0{
		return errors.New("divide by zero")
	}
	quo.Quo=args.A/args.B
	quo.Rem=args.A%args.B
	fmt.Println("call Arith.Divide ... ",time.Now())
	return nil
}

func main(){
	arith:=new(Arith)
	rpc.Register(arith)
	rpc.HandleHTTP()
	
	err:=http.ListenAndServe(":1234",nil)
	if err!=nil {
		fmt.Println("error -->",err.Error())
	}
}